package com.egao.common.manage.school;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.world.entity.WorldGameLink;
import com.egao.common.module.world.service.WorldGameLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 学校济世杯banner管
 * @author  lsj
 */
@Api(tags = "学校济世杯banner管理")
@RestController
@CrossOrigin
@RequestMapping("${api}")
public class SchoolWorldGameLinkController extends BaseController {
    @Autowired
    private WorldGameLinkService worldGameLinkService;


    @PreAuthorize("hasAuthority('school:world-game-link:list')")
    @ApiOperation("分页查询链接")
    @OperLog(value = "链接管理", desc = "分页查询链接")
    @GetMapping("/school/world-game-link/page")
    public PageResult<WorldGameLink> page(HttpServletRequest request) {
        PageParam<WorldGameLink> pageParam = new PageParam<>(request);
        pageParam.setDefaultOrder(new String[]{"sort"}, new String[]{"create_time"});
        return new PageResult<>(worldGameLinkService.WorldGameListPage(pageParam),pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school:world-game-link:list')")
    @ApiOperation("查询单个链接")
    @OperLog(value = "链接管理", desc = "查询单个链接")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "链接id", required = false, dataType = "Integer", paramType = "query"),
    })
    @GetMapping("/school/world-game-link/{id}")
    public JsonResult listGetId(@PathVariable Integer id) {
        return worldGameLinkService.getId(id);
    }

    @PreAuthorize("hasAuthority('school:world-game-link:save')")
    @ApiOperation("添加链接")
    @OperLog(value = "链接管理", desc = "添加链接", result = true)
    @PostMapping("/school/world-game-link/save")
    public JsonResult insert(@RequestBody WorldGameLink worldGameLink) {
        return worldGameLinkService.insertWorldGameLink(worldGameLink);
    }

    @PreAuthorize("hasAuthority('school:world-game-link:update')")
    @ApiOperation("修改链接")
    @OperLog(value = "链接管理", desc = "修改链接", result = true)
    @PutMapping("/school/world-game-link/update")
    public JsonResult update(@RequestBody WorldGameLink worldGameLink) {
        return worldGameLinkService.updateWorldGameLink(worldGameLink);
    }

    @PreAuthorize("hasAuthority('school:world-game-link:remove')")
    @ApiOperation("删除链接")
    @OperLog(value = "链接管理", desc = "删除链接", result = true)
    @DeleteMapping("/school/world-game-link/delete")
    public JsonResult delete(Integer id) {
        return worldGameLinkService.deleteById(id);
    }
}
